package idea;


import java.util.Scanner;

/**
 * @Author Stringzhua
 * @Date 2024/3/1 11:50
 * description:int数组冒泡排序
 */
public class ArrayTest {
    public static void main(String[] args) {
        MyTools myTools = new MyTools();
        Scanner scanner = new Scanner(System.in);
        Scanner scanner1 = new Scanner(System.in);
        Scanner scanner2 = new Scanner(System.in);
        int[] arr = {1, -3, 20, 9, -9, -98, -1, 16};
        myTools.bubble(arr);
        //输出排序后的arr
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "\t");
        }
    }
    //当idea在run一个文件时,会先编译成.class文件--->再运行
}
//查看类的继承关系ctrl+h
class Person{
    String name;
    int age;
    //构造器-->alt+insert
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {//无参构造器
    }
}
class MyTools {
    int temp = 0;

    //从小到大
    //冒泡排序
    public void bubble(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {//外层循环次数
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    //交换
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
}
